<?php
include( "inc/header.php" );
header("Content-Type:text/html;charset=utf-8");
login_check( );
if ($_GET['Action']=='save') {
	if (!isset($_POST['adminuser']) || empty($_POST['adminuser'])) {
		admin_showerr( "<li>管理员帐号不能为空</li>", "Admin_Admin.php", 0);
	}
	$sql = "UPDATE tun2_adminset SET name='".trim($_POST['adminuser'])."',";
	if ($_POST['password'] == $_POST['password1'] && !empty($_POST['password'])) {
		addlog( "修改管理员密码", $_SESSION['user_name'] );
		$sql .= "password='".md5(md5($_POST['password']))."',";
	}
	elseif ($_POST['password'] != $_POST['password1']) {
		admin_showerr( "<li>两次输入的密码不一致</li>", "Admin_Admin.php", 0);
	}
	$sql .= "lastip='".getip( )."' WHERE id=$_SESSION[uid]";
	addlog( "修改管理员帐号", $_SESSION['user_name'] );
	$db->query($sql);
	//admin_showerr( "<li>修改成功<br>重新登录请使用修改后的帐户及密码</li>", "Admin_Admin.php", 1);
	session_unset( );
	session_destroy( );
	work_back( "修改成功，请使用修改后的帐号及密码登录...", "Admin_Login.php" );
	exit( );
}

$db->query("SELECT * FROM tun2_adminset WHERE id=".$_SESSION['uid']);
$db->next_record();
?>
<table width="98%" border="1" align="center" cellpadding="5" cellspacing="0" class="table">
	<tr>
		<td>点击修改后，将使用修改后的帐号及密码重新登录</td>
	</tr>
</table>
<br>
<table width="98%" border="1" align="center" cellpadding="5" cellspacing="0" class="table">
<form id="form1" name="form1" method="post" action="Admin_Admin.php?Action=save">
  <tr>
    <td align="right">管理员帐号：</td>
    <td><label>
      <input name="adminuser" style="width:140px;" type="text" value="<?=$db->Record['name']?>" id="adminuser" />
    </label></td>
  </tr>
  <tr>
    <td align="right">新密码：</td>
    <td><label>
      <input name="password" style="width:140px;" type="password" id="password" />
    *不填，则密码保持不变</label></td>
  </tr>
  <tr>
    <td align="right">确认密码：</td>
    <td><label>
      <input name="password1" style="width:140px;" type="password" id="password1" />
    </label></td>
  </tr>
  <tr>
    <td align="right">&nbsp;</td>
    <td><label>
      <input type="submit" name="Submit" value="修 改" />
    </label></td>
  </tr>
      </form>
</table>